package com.inspur.gs.sbssdl.sbwhgl.sbrh.sbrh.back.bizactions;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.inspur.edp.bef.api.be.IBEManagerContext;
import com.inspur.edp.bef.api.be.IBEService;
import com.inspur.edp.bef.api.be.IBusinessEntity;
import com.inspur.edp.bef.api.lcp.ILcpFactory;
import com.inspur.edp.bef.api.lcp.IStandardLcp;
import com.inspur.edp.bef.api.services.IBefSessionManager;
import com.inspur.edp.bef.engine.entity.AssociationInfo;
import com.inspur.edp.bef.spi.action.AbstractManagerAction;
import com.inspur.edp.cef.entity.changeset.ModifyChangeDetail;
import com.inspur.edp.cef.entity.entity.IEntityData;
import io.iec.edp.caf.commons.utils.SpringBeanUtils;

import java.util.Map;

public class sbssSbrhRwupdateTaskMgrAction extends AbstractManagerAction<String> {
    private String lubricationInfo;

    public sbssSbrhRwupdateTaskMgrAction(IBEManagerContext managerContext, String lubricationInfo) {
        super(managerContext);
        this.lubricationInfo = lubricationInfo;
    }

    @Override
    public void execute() {
        SpringBeanUtils.getBean(IBefSessionManager.class).createSession();
        String configID = "0f9b3d1d-9d73-4deb-b5b1-7cb832da39e6";

        ObjectMapper mapper = new ObjectMapper();
        Map<String, Object> map = null;
        try {
//            ILcpFactory iLcpFactory = SpringBeanUtils.getBean(ILcpFactory.class);
//            IStandardLcp lcp = iLcpFactory.createLcpByBEId(configID);
//            map = mapper.readValue(lubricationInfo, Map.class);
//            IEntityData data = lcp.retrieve(map.get("id").toString()).getData();
//            ModifyChangeDetail change = new ModifyChangeDetail(data.getID());
//
//            Map<String, Object> zxrId = (Map<String, Object>) map.get("zxrId");
//            AssociationInfo zxrInfo = new AssociationInfo();
//            zxrInfo.setValue("zxrId", zxrId.get("zxrId"));
//            change.getPropertyChanges().put("zxrId", zxrInfo);
//            change.getPropertyChanges().put("zxrCode", map.get("zxrCode"));
//            change.getPropertyChanges().put("zxrName", map.get("zxrName"));
//
//            lcp.modify(change);
//            lcp.save();

        } catch (Exception e) {
            throw new RuntimeException(e.getMessage());
        } finally {
            SpringBeanUtils.getBean(IBefSessionManager.class).closeCurrentSession();
        }


    }

    private IBusinessEntity getEntity(String dataId) {
        return (IBusinessEntity) super.getBEManagerContext().getEntity(dataId);
    }

    private IBEService getMgr() {
        return (IBEService) super.getBEManagerContext().getBEManager();
    }
}